package com.ml.kafka.controller;

import com.ml.kafka.dto.KafkaMessage;
import com.ml.kafka.producer.Producer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;

/**
 * @author xr-8
 * @date 2021-05-05
 * @time 20:02
 */
@RestController
@RequestMapping(value = "/kafka", produces = MediaType.APPLICATION_JSON_VALUE)
public class KafkaController {

    @Autowired
    private Producer producer;

    @GetMapping("/send")
    public KafkaMessage sendKafkaMessage(@RequestParam(name="id") Long id,
                                         @RequestParam(name="name") String name,
                                         @RequestParam(name="age") Integer age){

        KafkaMessage kafkaMessage = KafkaMessage.builder().id(id)
                .name(name).age(age).build();
        producer.sendKafkaMessage(kafkaMessage);
        return kafkaMessage;
    }
}
